<template>
  <div>
    <el-dialog
      :title="obj.isAdd ? '会员编辑' : ''"
      :visible.sync="obj.isTrue"
      width="50%"
      @close="cancel()"
    >
      <el-form ref="form" :model="form" label-width="80px">
        <el-form-item label="手机号">
          <el-input v-model="form.phone"></el-input>
        </el-form-item>
        <el-form-item label="昵称">
          <el-input v-model="form.nickname"></el-input>
        </el-form-item>
        <el-form-item label="密码">
          <el-input v-model="form.password"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="cancel()">取 消</el-button>
        <el-button type="primary" @click="edit()" v-show="obj.isAdd">
          编 辑
        </el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import { mapGetters, mapActions } from "vuex";
import { successAlert, warningAlert } from "../../../util/alert";
import { memberInfo, memberEdit } from "../../../request/api";
export default {
  props: ["obj"],
  components: {},
  data() {
    return {
      form: {
        uid: "",
        nickname: "",
        phone: "",
        password: "",
        status: 1,
      },
    };
  },
  computed: {
    ...mapGetters({
      memberList: "member/list",
    }),
  },
  methods: {
    ...mapActions({
      reqMemberList: "member/reqChangeList",
    }),
    // 封装清空
    empty() {
      this.form = {
        uid: "",
        nickname: "",
        phone: "",
        password: "",
        status: 1,
      };
    },
    // 点击取消
    cancel() {
      this.obj.isTrue = false;
      this.empty();
    },
    // 获取一条信息
    getOne(uid) {
      memberInfo({ uid: uid }).then((res) => {
        this.form = res.data.list;
        this.form.uid = uid;
        this.form.password = "";
      });
    },
    // 点击了编辑
    edit() {
      memberEdit(this.form).then((res) => {
        if (res.data.code == 200) {
          successAlert(res.data.msg);
          this.cancel();
          this.reqMemberList();
        } else {
          warningAlert(res.data.msg);
        }
      });
    },
  },
  mounted() {},
};
</script>
<style scoped>
</style>